package com.atguigu.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/servlet4")
public class Servlet4 extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //行相关 GET/POST URL

        //请求相关 方法
        String method = req.getMethod();
        System.out.println("method:" + method);

        //协议相关
        String scheme = req.getScheme();
        System.out.println("scheme:" + scheme);

        //协议版本
        String protocol = req.getProtocol();
        System.out.println("protocol:" + protocol);

        //请求路径 统一资源标识符  资源定位的要求和规范(相对路径) 动物类
        String requestURI = req.getRequestURI();
        System.out.println("requestURI:" + requestURI);

        //请求URL 统一资源定位符  一个具体的资源路径(绝对路径)    哺乳动物类
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("requestURL:" + requestURL);

        //获取本地端口号

        int localPort = req.getLocalPort();
        System.out.println("localPort:" + localPort);

        //获取客户端IP地址

        String remoteAddr = req.getRemoteAddr();
        System.out.println("remoteAddr:" + remoteAddr);

        //获取客户端端口

        int remotePort = req.getRemotePort();
        System.out.println("remotePort:" + remotePort);

        //获取服务器端口号
        int serverPort = req.getServerPort();
        System.out.println("serverPort:" + serverPort);

        //获取客户端的主机名
        String remoteHost = req.getRemoteHost();
        System.out.println("remoteHost:" + remoteHost);

        //头相关 key:value

        //根据名字获取请求头

        String Accept = req.getHeader("Accept");
        System.out.println("Accept:" + Accept);

        //获取所有
        Enumeration<String> headers = req.getHeaderNames();
        while (headers.hasMoreElements()){
            String header = headers.nextElement();
            System.out.println(header);
        }

        //获取请求参数

    }
}
